home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / EMSIF230.ARJ / EMSTEST3.C < prev    next >
C/C++ Source or Header  |  1991-12-01  |  48KB  |  1,187 lines

  1. /***************************************************************************
  2. *   emstest3.c                                                             *
  3. *   MODULE:  EMSIF                                                         *
  4. *   OS:      DOS                                                           *
  5. *   VERSION: 1.2                                                           *
  6. *   DATE:    12/01/91                                                      *
  7. *                                                                          *
  8. *   Copyright (c) 1991 James W. Birdsall. All Rights Reserved.             *
  9. *                                                                          *
  10. *   Requires emsif.h, testutil.h, and emstest.h to compile.                *
  11. *   Compiles under Borland C++ 2.0, TC 2.0, or MSC 6.0A.                   *
  12. *                                                                          *
  13. *   Regression test and example for EMSIF. See EMSTEST.C for more info.    *
  14. *                                                                          *
  15. ***************************************************************************/
  16.  
  17. /*
  18. ** system includes <>
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <dos.h>
  24. #include <string.h>
  25.  
  26. /* include appropriate file according to compiler */
  27. #ifdef __TURBOC__
  28.  
  29. #include <alloc.h>
  30.  
  31. #else
  32.  
  33. #include <malloc.h>
  34.  
  35. #endif
  36.  
  37.  
  38. /*
  39. ** custom includes ""
  40. */
  41.  
  42. #include "testutil.h"
  43.  
  44. #include "emsif.h"
  45. #include "emstest.h"
  46.  
  47.  
  48. /*
  49. ** local #defines
  50. */
  51.  
  52. #define UCF         unsigned char far
  53. #define UCH         unsigned char huge
  54.  
  55. /*
  56. ** Define LMALLOC() and LFREE() to the appropriate functions, according to
  57. ** compiler.
  58. */
  59. #ifdef __TURBOC__
  60.  
  61. #define LMALLOC(kbytes)         farmalloc((((unsigned long) kbytes) * 1024L))
  62. #define LFREE(ptr)              farfree((ptr))
  63.  
  64. #else
  65.  
  66. #define LMALLOC(kbytes)         halloc((kbytes), 1024)
  67. #define LFREE(ptr)              hfree((ptr))
  68.  
  69. #endif
  70.  
  71. /*
  72. ** This macro is the same as TRIPLECHECK(), defined in EMSTEST.H, except that
  73. ** it calls functions which can handle a far pointer.
  74. */
  75. #define LTRIPLECHECK(fu, st, ex, fr1, fr2, fr3)                         \
  76.                          lfailcheck((fu), (st), (fr1), (fr2), (fr3));   \
  77.                          lweirdretchk((fu), (st), (fr1), (fr2), (fr3)); \
  78.                          lweirdcodechk((fu), (ex), (fr1), (fr2), (fr3))
  79.  
  80. /*
  81. ** Checks to see if a region of memory (possibly longer than 64K) is still
  82. ** incrementing word values, handles cleanup and exit if not.
  83. */
  84. #define WORDCHECK(buf, len, msg, start)                         \
  85.     if (lfarincwordcheck((buf), (len), (start)) != 0) {         \
  86.         printf("Copy corrupted %s.\n", (msg)); EMMfree(handle); \
  87.         LFREE(testbuf); exit(3); }
  88.  
  89. /*
  90. ** Check source and destination buffers, respectively.
  91. */
  92. #define SRCWORDCHECK(buf, len)    WORDCHECK(buf, len, "source buffer", 0)
  93. #define CPYWORDCHECK(buf, len)    WORDCHECK(buf, len, "copied bytes", 0)
  94.  
  95. /*
  96. ** Checks to see if a region of memory (possibly longer than 64K) is still
  97. ** filled with a given value, handles cleanup and exit if not.
  98. */
  99. #define MEMCHECK(buf, len, val)                           \
  100.     if (lfarmemcheck((UCF *) (buf), (len), (val)) != 0) { \
  101.         printf("Copy corrupted destination.\n");          \
  102.         EMMfree(handle); LFREE(testbuf); exit(3); }
  103.  
  104. /*
  105. ** Checks buffer for nonzero values.
  106. */
  107. #define ZEROCHECK(buf, len)       MEMCHECK(buf, len, '\0')
  108.  
  109.  
  110. /*
  111. ** misc: copyright strings, version macros, etc.
  112. */
  113.  
  114. /*
  115. ** typedefs
  116. */
  117.  
  118. /*
  119. ** global variables
  120. */
  121.  
  122. /* see EMSTEST.C for info */
  123. extern int testno;
  124. extern unsigned char far *frameptr[];
  125. extern char *gblmsg;
  126.  
  127.  
  128. /*
  129. ** static globals
  130. */
  131.  
  132. /*
  133. ** function prototypes
  134. */
  135.  
  136. static void do_nlongcopy_tests(void);
  137. static void do_ilongcopy_tests(void);
  138.  
  139. static void lfailcheck(char *function, int status, void far *tofree1,
  140.                                                      int tofree2, int tofree3);
  141. static void lnofailcheck(char *function, int status, void far *tofree1,
  142.                                                      int tofree2, int tofree3);
  143. static void lweirdretchk(char *function, int status, void far *tofree1,
  144.                                                      int tofree2, int tofree3);
  145. static void lweirdcodechk(char *function, int expected, void far *tofree1,
  146.                                                      int tofree2, int tofree3);
  147.  
  148.  
  149. /*
  150. ** functions
  151. */
  152.  
  153.  
  154. /***************************************************************************
  155. *   FUNCTION: DO_LONGCOPY_TESTS                                            *
  156. *                                                                          *
  157. *   DESCRIPTION:                                                           *
  158. *                                                                          *
  159. *       Central dispatching function for long copy tests.                  *
  160. *                                                                          *
  161. *   ENTRY:                                                                 *
  162. *                                                                          *
  163. *       Void.                                                              *
  164. *                                                                          *
  165. *   EXIT:                                                                  *
  166. *                                                                          *
  167. *       Void.                                                              *
  168. *                                                                          *
  169. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  170. *                                                                          *
  171. ***************************************************************************/
  172. void do_longcopy_tests(void)
  173. {
  174.     do_nlongcopy_tests();
  175.     do_ilongcopy_tests();
  176.     return;
  177. } /* end of do_longcopy_tests() */
  178.  
  179.  
  180. /***************************************************************************
  181. *   FUNCTION: DO_NLONGCOPY_TESTS  (STATIC)                                 *
  182. *                                                                          *
  183. *   DESCRIPTION:                                                           *
  184. *                                                                          *
  185. *       Tests EMSIF functions EMMcopyto() and EMMcopyfrom() with copies    *
  186. *       longer than one EMS page ( > 16384 bytes).                         *
  187. *                                                                          *
  188. *   ENTRY:                                                                 *
  189. *                                                                          *
  190. *       Void.                                                              *
  191. *                                                                          *
  192. *   EXIT:                                                                  *
  193. *                                                                          *
  194. *       Void.                                                              *
  195. *                                                                          *
  196. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  197. *                                                                          *
  198. ***************************************************************************/
  199. static void do_nlongcopy_tests(void)
  200. {
  201.     unsigned char far *testbuf;
  202.     int handle;
  203.     int status;
  204.     unsigned long ticks, totticks;
  205.     int loop;
  206.     unsigned long loop2;
  207.  
  208.     /* allocate memory to test against */
  209.     testbuf = (unsigned char far *) LMALLOC(80);
  210.     if (testbuf == (unsigned char far *) NULL)
  211.     {
  212.         printf("Cannot allocate test memory. Aborting.\n");
  213.         exit(1);
  214.     }
  215.  
  216.     /* now allocate some EMS to test with */
  217.     handle = test_EMMalloc(81920L);
  218.  
  219.     /* fill test buffer with incrementing word pattern */
  220.     lfarincwordfill(testbuf, 81920L, 0);
  221.  
  222.     /* fill EMS with a different pattern */
  223.     for (loop = 0; loop < 5; loop++)
  224.     {
  225.         test_EMMmappage(0, handle, loop);
  226.         FMEMSET(frameptr[0], 0, 16384);
  227.     }
  228.  
  229.     /* try a copy off end */
  230.     TESTHEADER();
  231.     printf("Calling EMMcopyto() with offset off end of EMS block.\n");
  232.     printf("Should fail.\n");
  233.     status = EMMcopyto(2L, testbuf, handle, 90000L);
  234.     lnofailcheck("EMMcopyto()", status, testbuf, handle, 0);
  235.     lweirdretchk("EMMcopyto()", status, testbuf, handle, 0);
  236.     lweirdcodechk("EMMcopyto()", EMM_BADOFFSET, testbuf, handle, 0);
  237.     SRCWORDCHECK(testbuf, 81920L);
  238.     for (loop = 0; loop < 5; loop++)
  239.     {
  240.         test_EMMmappage(0, handle, loop);
  241.         ZEROCHECK(frameptr[0], 16384L);
  242.     }
  243.     TESTTAILER();
  244.  
  245.     /* and another */
  246.     TESTHEADER();
  247.     printf("Calling EMMcopyto() with length that will run off end of block.\n");
  248.     printf("Should fail.\n");
  249.     status = EMMcopyto(30000L, testbuf, handle, 55000L);
  250.     lnofailcheck("EMMcopyto()", status, testbuf, handle, 0);
  251.     lweirdretchk("EMMcopyto()", status, testbuf, handle, 0);
  252.     lweirdcodechk("EMMcopyto()", EMM_BADOFFSET, testbuf, handle, 0);
  253.     SRCWORDCHECK(testbuf, 81920L);
  254.     for (loop = 0; loop < 5; loop++)
  255.     {
  256.         test_EMMmappage(0, handle, loop);
  257.         ZEROCHECK(frameptr[0], 16384L);
  258.     }
  259.     TESTTAILER();
  260.  
  261.     /* now try copy across page boundary */
  262.     TESTHEADER();
  263.     printf("Calling EMMcopyto() with copy across page boundary.\n");
  264.     printf("Should succeed.\n");
  265.     status = EMMcopyto(10000L, testbuf, handle, 10000L);
  266.     LTRIPLECHECK("EMMcopyto()", status, 0, testbuf, handle, 0);
  267.     SRCWORDCHECK(testbuf, 81920L);
  268.     test_EMMmappage(0, handle, 0);
  269.     test_EMMmappage(1, handle, 1);
  270.     CPYWORDCHECK((frameptr[0] + 10000), 10000L);
  271.     ZEROCHECK(frameptr[0], 10000L);
  272.     ZEROCHECK((frameptr[0] + 10000 + 10000), ((32768L - 10000L) - 10000L));
  273.     for (loop = 2; loop < 5; loop++)
  274.     {
  275.         test_EMMmappage(0, handle, loop);
  276.         ZEROCHECK(frameptr[0], 16384L);
  277.     }
  278.     printf("EMMcopyto() succeeded.\n");
  279.     TESTTAILER();
  280.  
  281.     /* restore destination pattern */
  282.     for (loop = 0; loop < 5; loop++)
  283.     {
  284.         test_EMMmappage(0, handle, loop);
  285.         FMEMSET(frameptr[0], 0, 16384);
  286.     }
  287.  
  288.     /* try copy across several page boundaries */
  289.     TESTHEADER();
  290.     printf("Calling EMMcopyto() with copy across several page boundaries.\n");
  291.     printf("Should succeed.\n");
  292.     status = EMMcopyto(50000L, testbuf, handle, 10000L);
  293.     LTRIPLECHECK("EMMcopyto()", status, 0, testbuf, handle, 0);
  294.     SRCWORDCHECK(testbuf, 81920L);
  295.     for (loop = 0; loop < 4; loop++)
  296.     {
  297.         test_EMMmappage(loop, handle, loop);
  298.     }
  299.     ZEROCHECK(frameptr[0], 10000L);
  300.     CPYWORDCHECK((frameptr[0] + 10000), 50000L);
  301.     ZEROCHECK((frameptr[0] + 10000U + 50000U), ((65536L - 10000L) - 50000L));
  302.     test_EMMmappage(0, handle, 4);
  303.     ZEROCHECK(frameptr[0], 16384L);
  304.     printf("EMMcopyto() succeeded.\n");
  305.     TESTTAILER();
  306.  
  307.     /* restore destination pattern */
  308.     for (loop = 0; loop < 5; loop++)
  309.     {
  310.         test_EMMmappage(0, handle, loop);
  311.         FMEMSET(frameptr[0], 0, 16384);
  312.     }
  313.  
  314.     /* try copy > 64K */
  315.     TESTHEADER();
  316.     printf("Calling EMMcopyto() with copy length > 64K.\n");
  317.     printf("Should succeed.\n");
  318.     ticks = get_tick();
  319.     status = EMMcopyto(81920L, testbuf, handle, 0L);
  320.     ticks = get_tick() - ticks;
  321.     LTRIPLECHECK("EMMcopyto()", status, 0, testbuf, handle, 0);
  322.     SRCWORDCHECK(testbuf, 81920L);
  323.     for (loop = 0; loop < 5; loop++)
  324.     {
  325.         test_EMMmappage(0, handle, loop);
  326.         WORDCHECK(frameptr[0], 16384L, "copied bytes", (8192U * loop));
  327.     }
  328.     printf("EMMcopyto() succeeded. 81920 bytes took %lu ticks.\n", ticks);
  329.     TESTTAILER();
  330.  
  331.     /* restore destination pattern */
  332.     for (loop = 0; loop < 5; loop++)
  333.     {
  334.         test_EMMmappage(0, handle, loop);
  335.         FMEMSET(frameptr[0], 0, 16384);
  336.     }
  337.  
  338.     /* do same copy by longwords */
  339.     TESTHEADER();
  340.     printf("Calling EMMcopyto() to copy 81920 bytes by longwords.\n");
  341.     printf("Should succeed, slowly.\n");
  342.     totticks = 0L;
  343.     for (loop2 = 0L; loop2 < 81920L; loop2 += 4L)
  344.     {
  345.         ticks = get_tick();
  346.         status = EMMcopyto(4L, (UCF *)(((UCH *) testbuf) + loop2),
  347.                                                                 handle, loop2);
  348.         totticks += (get_tick() - ticks);
  349.         LTRIPLECHECK("EMMcopyto()", status, 0, testbuf, handle, 0);
  350.     }
  351.     SRCWORDCHECK(testbuf, 81920L);
  352.     for (loop = 0; loop < 5; loop++)
  353.     {
  354.         test_EMMmappage(0, handle, loop);
  355.         WORDCHECK(frameptr[0], 16384L, "copied bytes", (8192U * loop));
  356.     }
  357.     printf("EMMcopyto() succeeded. 81920 bytes by longwords took %lu ticks.\n",
  358.                                                                      totticks);
  359.     TESTTAILER();
  360.  
  361.  
  362.     /* fill test buffer with zeros */
  363.     LFMEMSET(testbuf, '\0', 81920L);
  364.  
  365.     /* fill EMS with a different pattern */
  366.     for (loop = 0; loop < 5; loop++)
  367.     {
  368.         test_EMMmappage(0, handle, loop);
  369.         lfarincwordfill(frameptr[0], 16384L, (8192U * loop));
  370.     }
  371.  
  372.     /* try a copy off end */
  373.     TESTHEADER();
  374.     printf("Calling EMMcopyfrom() with offset off end of EMS block.\n");
  375.     printf("Should fail.\n");
  376.     status = EMMcopyfrom(2L, handle, 90000L, testbuf);
  377.     lnofailcheck("EMMcopyfrom()", status, testbuf, handle, 0);
  378.     lweirdretchk("EMMcopyfrom()", status, testbuf, handle, 0);
  379.     lweirdcodechk("EMMcopyfrom()", EMM_BADOFFSET, testbuf, handle, 0);
  380.     ZEROCHECK(testbuf, 81920L);
  381.     for (loop = 0; loop < 5; loop++)
  382.     {
  383.         test_EMMmappage(0, handle, loop);
  384.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  385.     }
  386.     TESTTAILER();
  387.  
  388.     /* and another */
  389.     TESTHEADER();
  390.     printf("Calling EMMcopyfrom() with length that will run off end of block.\n");
  391.     printf("Should fail.\n");
  392.     status = EMMcopyfrom(30000L, handle, 55000L, testbuf);
  393.     lnofailcheck("EMMcopyfrom()", status, testbuf, handle, 0);
  394.     lweirdretchk("EMMcopyfrom()", status, testbuf, handle, 0);
  395.     lweirdcodechk("EMMcopyfrom()", EMM_BADOFFSET, testbuf, handle, 0);
  396.     ZEROCHECK(testbuf, 81920L);
  397.     for (loop = 0; loop < 5; loop++)
  398.     {
  399.         test_EMMmappage(0, handle, loop);
  400.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  401.     }
  402.     TESTTAILER();
  403.  
  404.     /* now try copy across page boundary */
  405.     TESTHEADER();
  406.     printf("Calling EMMcopyfrom() with copy across page boundary.\n");
  407.     printf("Should succeed.\n");
  408.     status = EMMcopyfrom(10000L, handle, 0L, (testbuf + 10000));
  409.     LTRIPLECHECK("EMMcopyfrom()", status, 0, testbuf, handle, 0);
  410.     ZEROCHECK(testbuf, 10000L);
  411.     CPYWORDCHECK((testbuf + 10000), 10000L);
  412.     ZEROCHECK((testbuf + 10000 + 10000), ((81920L - 10000L) - 10000L));
  413.     for (loop = 0; loop < 5; loop++)
  414.     {
  415.         test_EMMmappage(0, handle, loop);
  416.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  417.     }
  418.     printf("EMMcopyfrom() succeeded.\n");
  419.     TESTTAILER();
  420.  
  421.     /* restore destination pattern */
  422.     LFMEMSET(testbuf, '\0', 81920L);
  423.  
  424.     /* try copy across several page boundaries */
  425.     TESTHEADER();
  426.     printf("Calling EMMcopyfrom() with copy across several page boundaries.\n");
  427.     printf("Should succeed.\n");
  428.     status = EMMcopyfrom(50000L, handle, 0L, (testbuf + 10000));
  429.     LTRIPLECHECK("EMMcopyfrom()", status, 0, testbuf, handle, 0);
  430.     ZEROCHECK(testbuf, 10000L);
  431.     CPYWORDCHECK((testbuf + 10000), 50000L);
  432.     ZEROCHECK((testbuf + 10000U + 50000U), ((81920L - 10000L) - 50000L));
  433.     for (loop = 0; loop < 5; loop++)
  434.     {
  435.         test_EMMmappage(0, handle, loop);
  436.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  437.     }
  438.     printf("EMMcopyfrom() succeeded.\n");
  439.     TESTTAILER();
  440.  
  441.     /* restore destination pattern */
  442.     LFMEMSET(testbuf, '\0', 81920L);
  443.  
  444.     /* try copy > 64K */
  445.     TESTHEADER();
  446.     printf("Calling EMMcopyfrom() with copy length > 64K.\n");
  447.     printf("Should succeed.\n");
  448.     ticks = get_tick();
  449.     status = EMMcopyfrom(81920L, handle, 0L, testbuf);
  450.     ticks = get_tick() - ticks;
  451.     LTRIPLECHECK("EMMcopyfrom()", status, 0, testbuf, handle, 0);
  452.     CPYWORDCHECK(testbuf, 81920L);
  453.     for (loop = 0; loop < 5; loop++)
  454.     {
  455.         test_EMMmappage(0, handle, loop);
  456.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  457.     }
  458.     printf("EMMcopyfrom() succeeded. 81920 bytes took %lu ticks.\n", ticks);
  459.     TESTTAILER();
  460.  
  461.     /* restore destination pattern */
  462.     LFMEMSET(testbuf, '\0', 81920L);
  463.  
  464.     /* do same copy by longwords */
  465.     TESTHEADER();
  466.     printf("Calling EMMcopyfrom() to copy 81920 bytes by longwords.\n");
  467.     printf("Should succeed, slowly.\n");
  468.     totticks = 0L;
  469.     for (loop2 = 0L; loop2 < 81920L; loop2 += 4L)
  470.     {
  471.         ticks = get_tick();
  472.         status = EMMcopyfrom(4L, handle, loop2,
  473.                                            (UCF *)(((UCH *) testbuf) + loop2));
  474.         totticks += (get_tick() - ticks);
  475.         LTRIPLECHECK("EMMcopyfrom()", status, 0, testbuf, handle, 0);
  476.     }
  477.     CPYWORDCHECK(testbuf, 81920L);
  478.     for (loop = 0; loop < 5; loop++)
  479.     {
  480.         test_EMMmappage(0, handle, loop);
  481.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  482.     }
  483.     printf("EMMcopyfrom() succeeded. 81920 bytes by longwords took %lu ticks.\n",
  484.                                                                      totticks);
  485.     TESTTAILER();
  486.  
  487.  
  488.     /* clean up */
  489.     test_EMMfree(handle);
  490.     LFREE(testbuf);
  491.  
  492.     return;
  493. } /* end of do_nlongcopy_tests() */
  494.  
  495.  
  496. /***************************************************************************
  497. *   FUNCTION: DO_ILONGCOPY_TESTS  (STATIC)                                 *
  498. *                                                                          *
  499. *   DESCRIPTION:                                                           *
  500. *                                                                          *
  501. *       Tests EMSIF functions _EMMicopyto() and _EMMicopyfrom() with       *
  502. *       copies longer than one EMS page ( > 16384 bytes).                  *
  503. *                                                                          *
  504. *   ENTRY:                                                                 *
  505. *                                                                          *
  506. *       Void.                                                              *
  507. *                                                                          *
  508. *   EXIT:                                                                  *
  509. *                                                                          *
  510. *       Void.                                                              *
  511. *                                                                          *
  512. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  513. *                                                                          *
  514. ***************************************************************************/
  515. void do_ilongcopy_tests(void)
  516. {
  517.     unsigned char far *testbuf;
  518.     int handle;
  519.     int status;
  520.     unsigned long ticks, totticks;
  521.     int loop;
  522.  
  523.     /* allocate memory to test against */
  524.     testbuf = (unsigned char far *) LMALLOC(80);
  525.     if (testbuf == (unsigned char far *) NULL)
  526.     {
  527.         printf("Cannot allocate test memory. Aborting.\n");
  528.         exit(1);
  529.     }
  530.  
  531.     /* now allocate some EMS to test with */
  532.     handle = test_EMMalloc(81920L);
  533.  
  534.     /* fill test buffer with incrementing word pattern */
  535.     lfarincwordfill(testbuf, 81920L, 0);
  536.  
  537.     /* fill EMS with a different pattern */
  538.     for (loop = 0; loop < 5; loop++)
  539.     {
  540.         test_EMMmappage(0, handle, loop);
  541.         FMEMSET(frameptr[0], 0, 16384);
  542.     }
  543.  
  544.     /* try a copy off end */
  545.     TESTHEADER();
  546.     printf("Calling _EMMicopyto() with offset off end of EMS block.\n");
  547.     printf("Should fail.\n");
  548.     status = EMMicopyto(2L, 2, 2, testbuf, handle, 90000L);
  549.     lnofailcheck("_EMMicopyto()", status, testbuf, handle, 0);
  550.     lweirdretchk("_EMMicopyto()", status, testbuf, handle, 0);
  551.     lweirdcodechk("_EMMicopyto()", EMM_BADOFFSET, testbuf, handle, 0);
  552.     SRCWORDCHECK(testbuf, 81920L);
  553.     for (loop = 0; loop < 5; loop++)
  554.     {
  555.         test_EMMmappage(0, handle, loop);
  556.         ZEROCHECK(frameptr[0], 16384L);
  557.     }
  558.     TESTTAILER();
  559.  
  560.     /* and another */
  561.     TESTHEADER();
  562.     printf("Calling _EMMicopyto() with length that will run off end of block.\n");
  563.     printf("Should fail.\n");
  564.     status = EMMicopyto(10000L, 2, 2, testbuf, handle, 55000L);
  565.     lnofailcheck("_EMMicopyto()", status, testbuf, handle, 0);
  566.     lweirdretchk("_EMMicopyto()", status, testbuf, handle, 0);
  567.     lweirdcodechk("_EMMicopyto()", EMM_BADOFFSET, testbuf, handle, 0);
  568.     SRCWORDCHECK(testbuf, 81920L);
  569.     for (loop = 0; loop < 5; loop++)
  570.     {
  571.         test_EMMmappage(0, handle, loop);
  572.         ZEROCHECK(frameptr[0], 16384L);
  573.     }
  574.     TESTTAILER();
  575.  
  576.     /* now try copy across page boundary, aligned */
  577.     TESTHEADER();
  578.     printf(
  579.      "Calling _EMMicopyto() with copy across page boundary, element aligned.\n");
  580.     printf("Should succeed.\n");
  581.     status = EMMicopyto(2500L, 2, 2, testbuf, handle, 10000L);
  582.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  583.     status = EMMicopyto(2500L, 2, 2, (testbuf + 2), handle, 10002L);
  584.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  585.     SRCWORDCHECK(testbuf, 81920L);
  586.     test_EMMmappage(0, handle, 0);
  587.     test_EMMmappage(1, handle, 1);
  588.     CPYWORDCHECK((frameptr[0] + 10000), 10000L);
  589.     ZEROCHECK(frameptr[0], 10000L);
  590.     ZEROCHECK((frameptr[0] + 10000 + 10000), ((32768L - 10000L) - 10000L));
  591.     for (loop = 2; loop < 5; loop++)
  592.     {
  593.         test_EMMmappage(0, handle, loop);
  594.         ZEROCHECK(frameptr[0], 16384L);
  595.     }
  596.     printf("_EMMicopyto() succeeded.\n");
  597.     TESTTAILER();
  598.  
  599.     /* restore destination pattern */
  600.     for (loop = 0; loop < 5; loop++)
  601.     {
  602.         test_EMMmappage(0, handle, loop);
  603.         FMEMSET(frameptr[0], 0, 16384);
  604.     }
  605.  
  606.     /* try copy across several page boundaries, element not aligned */
  607.     TESTHEADER();
  608.     printf("Calling _EMMicopyto() with copy across page boundary, %s\n",
  609.                                                        "element not aligned.");
  610.     printf("Should succeed.\n");
  611.     status = EMMicopyto(5000L, 5, 5, testbuf, handle, 10000L);
  612.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  613.     status = EMMicopyto(5000L, 5, 5, (testbuf + 5), handle, 10005L);
  614.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  615.     SRCWORDCHECK(testbuf, 81920L);
  616.     for (loop = 0; loop < 4; loop++)
  617.     {
  618.         test_EMMmappage(loop, handle, loop);
  619.     }
  620.     ZEROCHECK(frameptr[0], 10000L);
  621.     CPYWORDCHECK((frameptr[0] + 10000), 50000L);
  622.     ZEROCHECK((frameptr[0] + 10000U + 50000U), ((65536L - 10000L) - 50000L));
  623.     test_EMMmappage(0, handle, 4);
  624.     ZEROCHECK(frameptr[0], 16384L);
  625.     printf("_EMMicopyto() succeeded.\n");
  626.     TESTTAILER();
  627.  
  628.     /* restore destination pattern */
  629.     for (loop = 0; loop < 5; loop++)
  630.     {
  631.         test_EMMmappage(0, handle, loop);
  632.         FMEMSET(frameptr[0], 0, 16384);
  633.     }
  634.  
  635.     /* do full copy by longwords */
  636.     TESTHEADER();
  637.     printf(
  638.        "Calling _EMMicopyto() to copy 81920 bytes by longwords, two passes.\n");
  639.     printf("Should succeed.\n");
  640.     ticks = get_tick();
  641.     status = EMMicopyto(10240L, 4, 4, testbuf, handle, 0L);
  642.     totticks = get_tick() - ticks;
  643.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  644.     ticks = get_tick();
  645.     status = EMMicopyto(10240L, 4, 4, (testbuf + 4), handle, 4L);
  646.     totticks += (get_tick() - ticks);
  647.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  648.     SRCWORDCHECK(testbuf, 81920L);
  649.     for (loop = 0; loop < 5; loop++)
  650.     {
  651.         test_EMMmappage(0, handle, loop);
  652.         WORDCHECK(frameptr[0], 16384L, "copied bytes", (8192U * loop));
  653.     }
  654.     printf("_EMMicopyto() succeeded. 81920 bytes by longwords took %lu ticks.\n",
  655.                                                                      totticks);
  656.     TESTTAILER();
  657.  
  658.  
  659.     /* restore destination pattern */
  660.     for (loop = 0; loop < 5; loop++)
  661.     {
  662.         test_EMMmappage(0, handle, loop);
  663.         FMEMSET(frameptr[0], 0, 16384);
  664.     }
  665.  
  666.     /* try copy with maximum skip */
  667.     TESTHEADER();
  668.     printf("Calling _EMMicopyto() with skip of 32768.\n");
  669.     printf("Should succeed.\n");
  670.     status = EMMicopyto(2L, 8192, 32768U, testbuf, handle, 0L);
  671.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  672.     status = EMMicopyto(2L, 8192, 32768U, (testbuf + 8192), handle, 8192L);
  673.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  674.     SRCWORDCHECK(testbuf, 81920);
  675.     test_EMMmappage(0, handle, 0);
  676.     WORDCHECK(frameptr[0], 16384L, "copied bytes", 0);
  677.     test_EMMmappage(0, handle, 1);
  678.     ZEROCHECK(frameptr[0], 16384);
  679.     test_EMMmappage(0, handle, 2);
  680.     ZEROCHECK(frameptr[0], 8192);
  681.     WORDCHECK((frameptr[0] + 8192), 8192L, "copied bytes", (4096 * 5));
  682.     test_EMMmappage(0, handle, 3);
  683.     WORDCHECK(frameptr[0], 8192L, "copied bytes", (8192U * 3));
  684.     ZEROCHECK((frameptr[0] + 8192), 8192);
  685.     test_EMMmappage(0, handle, 4);
  686.     ZEROCHECK(frameptr[0], 16384);
  687.     printf("_EMMicopyto() succeeded.\n");
  688.     TESTTAILER();
  689.  
  690.     /* restore destination pattern */
  691.     for (loop = 0; loop < 5; loop++)
  692.     {
  693.         test_EMMmappage(0, handle, loop);
  694.         FMEMSET(frameptr[0], 0, 16384);
  695.     }
  696.  
  697.     /* try copy with maximum element size */
  698.     TESTHEADER();
  699.     printf("Calling _EMMicopyto() with element size of 16384.\n");
  700.     printf("Should succeed.\n");
  701.     status = EMMicopyto(3L, 16384, 16384, testbuf, handle, 0L);
  702.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  703.     SRCWORDCHECK(testbuf, 81920);
  704.     test_EMMmappage(0, handle, 0);
  705.     WORDCHECK(frameptr[0], 16384L, "copied bytes", 0);
  706.     test_EMMmappage(0, handle, 1);
  707.     ZEROCHECK(frameptr[0], 16384);
  708.     test_EMMmappage(0, handle, 2);
  709.     WORDCHECK(frameptr[0], 16384L, "copied bytes", (8192U * 2));
  710.     test_EMMmappage(0, handle, 3);
  711.     ZEROCHECK(frameptr[0], 16384);
  712.     test_EMMmappage(0, handle, 4);
  713.     WORDCHECK(frameptr[0], 16384L, "copied bytes", (8192U * 4U));
  714.     status = EMMicopyto(2L, 16384, 16384, (testbuf + 16384), handle, 16384L);
  715.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  716.     for (loop = 0; loop < 5; loop++)
  717.     {
  718.         test_EMMmappage(0, handle, loop);
  719.         WORDCHECK(frameptr[0], 16384L, "copied bytes", (8192U * loop));
  720.     }
  721.     status = EMMicopyto(2L, 16384, 16384, (testbuf + 8192), handle, 8192L);
  722.     for (loop = 0; loop < 5; loop++)
  723.     {
  724.         test_EMMmappage(0, handle, loop);
  725.         WORDCHECK(frameptr[0], 16384L, "copied bytes", (8192U * loop));
  726.     }
  727.     printf("_EMMicopyto() succeeded.\n");
  728.     TESTTAILER();
  729.  
  730.     /* restore destination pattern */
  731.     for (loop = 0; loop < 5; loop++)
  732.     {
  733.         test_EMMmappage(0, handle, loop);
  734.         FMEMSET(frameptr[0], 0, 16384);
  735.     }
  736.  
  737.     /* try copy with max skip and max element */
  738.     TESTHEADER();
  739.     printf("Calling _EMMicopyto() with skip 32768, element size 16384.\n");
  740.     printf("Should succeed.\n");
  741.     status = EMMicopyto(2L, 16384, 32768U, testbuf, handle, 0L);
  742.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  743.     SRCWORDCHECK(testbuf, 81920L);
  744.     test_EMMmappage(0, handle, 0);
  745.     WORDCHECK(frameptr[0], 16384L, "copied bytes", 0);
  746.     test_EMMmappage(0, handle, 1);
  747.     ZEROCHECK(frameptr[0], 16384);
  748.     test_EMMmappage(0, handle, 2);
  749.     ZEROCHECK(frameptr[0], 16384);
  750.     test_EMMmappage(0, handle, 3);
  751.     WORDCHECK(frameptr[0], 16384L, "copied bytes", (8192U * 3));
  752.     test_EMMmappage(0, handle, 4);
  753.     ZEROCHECK(frameptr[0], 16384);
  754.     printf("_EMMicopyto() succeeded.\n");
  755.     TESTTAILER();
  756.  
  757.  
  758.     /* fill test buffer with zeros */
  759.     LFMEMSET(testbuf, '\0', 81920L);
  760.  
  761.     /* fill EMS with a different pattern */
  762.     for (loop = 0; loop < 5; loop++)
  763.     {
  764.         test_EMMmappage(0, handle, loop);
  765.         lfarincwordfill(frameptr[0], 16384L, (8192U * loop));
  766.     }
  767.  
  768.     /* try a copy off end */
  769.     TESTHEADER();
  770.     printf("Calling _EMMicopyfrom() with offset off end of EMS block.\n");
  771.     printf("Should fail.\n");
  772.     status = EMMicopyfrom(2L, 2, 2, handle, 90000L, testbuf);
  773.     lnofailcheck("_EMMicopyfrom()", status, testbuf, handle, 0);
  774.     lweirdretchk("_EMMicopyfrom()", status, testbuf, handle, 0);
  775.     lweirdcodechk("_EMMicopyfrom()", EMM_BADOFFSET, testbuf, handle, 0);
  776.     ZEROCHECK(testbuf, 81920L);
  777.     for (loop = 0; loop < 5; loop++)
  778.     {
  779.         test_EMMmappage(0, handle, loop);
  780.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  781.     }
  782.     TESTTAILER();
  783.  
  784.     /* and another */
  785.     TESTHEADER();
  786.     printf("Calling _EMMicopyfrom() with length that will run off end of block.\n");
  787.     printf("Should fail.\n");
  788.     status = EMMicopyfrom(10000L, 2, 2, handle, 55000L, testbuf);
  789.     lnofailcheck("_EMMicopyfrom()", status, testbuf, handle, 0);
  790.     lweirdretchk("_EMMicopyfrom()", status, testbuf, handle, 0);
  791.     lweirdcodechk("_EMMicopyfrom()", EMM_BADOFFSET, testbuf, handle, 0);
  792.     ZEROCHECK(testbuf, 81920L);
  793.     for (loop = 0; loop < 5; loop++)
  794.     {
  795.         test_EMMmappage(0, handle, loop);
  796.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  797.     }
  798.     TESTTAILER();
  799.  
  800.     /* now try copy across page boundary, aligned */
  801.     TESTHEADER();
  802.     printf("Calling _EMMicopyfrom() with copy across page boundary, %s\n",
  803.                                                            "element aligned.");
  804.     printf("Should succeed.\n");
  805.     status = EMMicopyfrom(2500L, 2, 2, handle, 0L, (testbuf + 10000));
  806.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  807.     status = EMMicopyfrom(2500L, 2, 2, handle, 2L, (testbuf + 10002));
  808.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  809.     ZEROCHECK(testbuf, 10000L);
  810.     CPYWORDCHECK((testbuf + 10000), 10000L);
  811.     ZEROCHECK((testbuf + 10000 + 10000), ((81920L - 10000L) - 10000L));
  812.     for (loop = 0; loop < 5; loop++)
  813.     {
  814.         test_EMMmappage(0, handle, loop);
  815.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  816.     }
  817.     printf("_EMMicopyfrom() succeeded.\n");
  818.     TESTTAILER();
  819.  
  820.     /* restore destination pattern */
  821.     LFMEMSET(testbuf, '\0', 81920L);
  822.  
  823.     /* try copy across several page boundaries, element not aligned */
  824.     TESTHEADER();
  825.     printf("Calling _EMMicopyfrom() with copy across page boundary, %s\n",
  826.                                                        "element not aligned.");
  827.     printf("Should succeed.\n");
  828.     status = EMMicopyfrom(5000L, 5, 5, handle, 0L, (testbuf + 10000));
  829.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  830.     status = EMMicopyfrom(5000L, 5, 5, handle, 5L, (testbuf + 10005));
  831.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  832.     for (loop = 0; loop < 5; loop++)
  833.     {
  834.         test_EMMmappage(0, handle, loop);
  835.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  836.     }
  837.     ZEROCHECK(testbuf, 10000L);
  838.     CPYWORDCHECK((testbuf + 10000), 50000L);
  839.     ZEROCHECK((testbuf + 10000U + 50000U), ((81920L - 10000L) - 50000L));
  840.     printf("_EMMicopyfrom() succeeded.\n");
  841.     TESTTAILER();
  842.  
  843.     /* restore destination pattern */
  844.     LFMEMSET(testbuf, '\0', 81920L);
  845.  
  846.     /* do full copy by longwords */
  847.     TESTHEADER();
  848.     printf(
  849.      "Calling _EMMicopyfrom() to copy 81920 bytes by longwords, two passes.\n");
  850.     printf("Should succeed.\n");
  851.     ticks = get_tick();
  852.     status = EMMicopyfrom(10240L, 4, 4, handle, 0L, testbuf);
  853.     totticks = get_tick() - ticks;
  854.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  855.     ticks = get_tick();
  856.     status = EMMicopyfrom(10240L, 4, 4, handle, 4L, (testbuf + 4));
  857.     totticks += (get_tick() - ticks);
  858.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  859.     CPYWORDCHECK(testbuf, 81920L);
  860.     for (loop = 0; loop < 5; loop++)
  861.     {
  862.         test_EMMmappage(0, handle, loop);
  863.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  864.     }
  865.     printf("_EMMicopyfrom() succeeded. 81920 bytes by longwords took %lu ticks.\n",
  866.                                                                      totticks);
  867.     TESTTAILER();
  868.  
  869.     /* restore destination pattern */
  870.     LFMEMSET(testbuf, '\0', 81920L);
  871.  
  872.     /* try copy with maximum skip */
  873.     TESTHEADER();
  874.     printf("Calling _EMMicopyfrom() with skip of 32768.\n");
  875.     printf("Should succeed.\n");
  876.     status = EMMicopyfrom(2L, 8192, 32768U, handle, 0L, testbuf);
  877.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  878.     status = EMMicopyfrom(2L, 8192, 32768U, handle, 8192L, (testbuf + 8192));
  879.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  880.     for (loop = 0; loop < 5; loop++)
  881.     {
  882.         test_EMMmappage(0, handle, loop);
  883.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  884.     }
  885.     WORDCHECK(testbuf, 16384L, "copied bytes", 0);
  886.     ZEROCHECK((testbuf + 16384), (16384L + 8192L));
  887.     WORDCHECK((testbuf + (32768U + 8192U)), 16384L, "copied bytes", (4096*5));
  888.     ZEROCHECK((testbuf + (8192U * 7U)), (16384 + 8192));
  889.     printf("_EMMicopyfrom() succeeded.\n");
  890.     TESTTAILER();
  891.  
  892.     /* restore destination pattern */
  893.     LFMEMSET(testbuf, '\0', 81920L);
  894.  
  895.     /* try copy with maximum element size */
  896.     TESTHEADER();
  897.     printf("Calling _EMMicopyfrom() with element size of 16384.\n");
  898.     printf("Should succeed.\n");
  899.     status = EMMicopyfrom(3L, 16384, 16384, handle, 0L, testbuf);
  900.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  901.     for (loop = 0; loop < 5; loop++)
  902.     {
  903.         test_EMMmappage(0, handle, loop);
  904.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  905.     }
  906.     WORDCHECK(testbuf, 16384L, "copied bytes", 0);
  907.     ZEROCHECK((testbuf + 16384), 16384);
  908.     WORDCHECK((testbuf + 32768U), 16384L, "copied bytes", (8192U * 2));
  909.     ZEROCHECK((testbuf + (16384U * 3U)), 16384);
  910.     WORDCHECK(MK_FP((FP_SEG(testbuf) + 0x1000), FP_OFF(testbuf)), 16384L, "copied bytes", (8192U * 4));
  911.     status = EMMicopyfrom(2L, 16384, 16384, handle, 16384L, (testbuf + 16384));
  912.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  913.     WORDCHECK(testbuf, 81920L, "copied bytes", 0);
  914.     status = EMMicopyfrom(2L, 16384, 16384, handle, 8192L, (testbuf + 8192));
  915.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  916.     WORDCHECK(testbuf, 81920L, "copied bytes", 0);
  917.     printf("_EMMicopyfrom() succeeded.\n");
  918.     TESTTAILER();
  919.  
  920.     /* restore destination pattern */
  921.     LFMEMSET(testbuf, '\0', 81920L);
  922.  
  923.     /* try copy with max skip and max element */
  924.     TESTHEADER();
  925.     printf("Calling _EMMicopyfrom() with skip 32768, element size 16384.\n");
  926.     printf("Should succeed.\n");
  927.     status = EMMicopyfrom(2L, 16384, 32768U, handle, 0L, testbuf);
  928.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  929.     for (loop = 0; loop < 5; loop++)
  930.     {
  931.         test_EMMmappage(0, handle, loop);
  932.         WORDCHECK(frameptr[0], 16384L, "source buffer", (8192U * loop));
  933.     }
  934.     WORDCHECK(testbuf, 16384L, "copied bytes", 0);
  935.     ZEROCHECK((testbuf + 16384), 32768L);
  936.     WORDCHECK((testbuf + (16384U * 3U)), 16384L, "copied bytes", (8192U * 3));
  937.     ZEROCHECK(MK_FP((FP_SEG(testbuf) + 0x1000), FP_OFF(testbuf)), 16384);
  938.     printf("_EMMicopyfrom() succeeded.\n");
  939.     TESTTAILER();
  940.  
  941.  
  942.     /* fill test buffer with incrementing word pattern */
  943.     lfarincwordfill(testbuf, 81920L, 0);
  944.  
  945.     /* fill EMS with a different pattern */
  946.     for (loop = 0; loop < 5; loop++)
  947.     {
  948.         test_EMMmappage(0, handle, loop);
  949.         FMEMSET(frameptr[0], 0, 16384);
  950.     }
  951.  
  952.     /* try interleaved copy and back */
  953.     TESTHEADER();
  954.     printf("Calling _EMMicopyto() with source and dest skip different.\n");
  955.     printf("Then calling _EMMicopyfrom() to restore interleave.\n");
  956.     printf("Should succeed.\n");
  957.     status = _EMMicopyto(20480L, 2, 2, testbuf, handle, 0L, 0);
  958.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  959.     status = _EMMicopyto(20480L, 2, 2, (testbuf + 2), handle, 40960L, 0);
  960.     LTRIPLECHECK("_EMMicopyto()", status, 0, testbuf, handle, 0);
  961.     SRCWORDCHECK(testbuf, 81920L);
  962.     status = _EMMicopyfrom(20480L, 2, 0, handle, 0L, testbuf, 2);
  963.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  964.     status = _EMMicopyfrom(20480L, 2, 0, handle, 40960L, (testbuf + 2), 2);
  965.     LTRIPLECHECK("_EMMicopyfrom()", status, 0, testbuf, handle, 0);
  966.     CPYWORDCHECK(testbuf, 81920);
  967.     TESTTAILER();
  968.  
  969.  
  970.     /* clean up */
  971.     test_EMMfree(handle);
  972.     LFREE(testbuf);
  973.  
  974.     return;
  975. } /* end of do_ilongcopy_tests() */
  976.  
  977.  
  978. /*
  979. ** The following group of functions is essentially the same as the
  980. ** similarly-named functions in EMSTEST.C, but can handle a far pointer.
  981. */
  982.  
  983.  
  984. /***************************************************************************
  985. *   FUNCTION: LWEIRDRETCHK  (STATIC)                                       *
  986. *                                                                          *
  987. *   DESCRIPTION:                                                           *
  988. *                                                                          *
  989. *       This function checks to see if the status value passed to it is    *
  990. *       either 0 or EMMOOPS, and assumes something has gone wrong if it    *
  991. *       is not. If something has gone wrong, does some clean up before     *
  992. *       exiting.                                                           *
  993. *                                                                          *
  994. *   ENTRY:                                                                 *
  995. *                                                                          *
  996. *       function - name of function which may have goofed                  *
  997. *       status   - status value to check                                   *
  998. *       tofree1  - conventional memory block to be freed on exit. Not      *
  999. *                  freed if NULL.                                          *
  1000. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1001. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1002. *                                                                          *
  1003. *   EXIT:                                                                  *
  1004. *                                                                          *
  1005. *       Void, or may not return.                                           *
  1006. *                                                                          *
  1007. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1008. *                                                                          *
  1009. ***************************************************************************/
  1010. static void lweirdretchk(char *function, int status, void far *tofree1,
  1011.                                                       int tofree2, int tofree3)
  1012. {
  1013.     if ((status != EMMOOPS) && (status != 0))
  1014.     {
  1015.         printf("%s returned weird value %d, code 0x%X.\n", function, status,
  1016.                                                      (unsigned int) _EMMerror);
  1017.         if (tofree1 != (void *) NULL)
  1018.         {
  1019.             LFREE(tofree1);
  1020.         }
  1021.         if (tofree2 != 0)
  1022.         {
  1023.             EMMfree(tofree2);
  1024.         }
  1025.         if (tofree3 != 0)
  1026.         {
  1027.             EMMfree(tofree3);
  1028.         }
  1029.         exit(3);
  1030.     }
  1031.  
  1032.     return;
  1033. } /* end of lweirdretchk() */
  1034.  
  1035.  
  1036. /***************************************************************************
  1037. *   FUNCTION: LWEIRDCODECHK  (STATIC)                                      *
  1038. *                                                                          *
  1039. *   DESCRIPTION:                                                           *
  1040. *                                                                          *
  1041. *       This function checks to see if the EMSIF error code value matches  *
  1042. *       the expected value, and assumes something has gone wrong if it     *
  1043. *       does not. If something has gone wrong, does some clean up before   *
  1044. *       exiting.                                                           *
  1045. *                                                                          *
  1046. *   ENTRY:                                                                 *
  1047. *                                                                          *
  1048. *       function - name of function which may have goofed                  *
  1049. *       expected - expected value of _EMMerror                             *
  1050. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1051. *                  freed if NULL.                                          *
  1052. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1053. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1054. *                                                                          *
  1055. *   EXIT:                                                                  *
  1056. *                                                                          *
  1057. *       Void, or may not return.                                           *
  1058. *                                                                          *
  1059. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1060. *                                                                          *
  1061. ***************************************************************************/
  1062. static void lweirdcodechk(char *function, int expected, void far *tofree1,
  1063.                                                       int tofree2, int tofree3)
  1064. {
  1065.     if ((int) _EMMerror != expected)
  1066.     {
  1067.         printf("%s returned unexpected code 0x%X.\n", function,
  1068.                                                      (unsigned int) _EMMerror);
  1069.         if (tofree1 != (void *) NULL)
  1070.         {
  1071.             LFREE(tofree1);
  1072.         }
  1073.         if (tofree2 != 0)
  1074.         {
  1075.             EMMfree(tofree2);
  1076.         }
  1077.         if (tofree3 != 0)
  1078.         {
  1079.             EMMfree(tofree3);
  1080.         }
  1081.         exit(3);
  1082.     }
  1083.  
  1084.     return;
  1085. } /* end of lweirdcodechk() */
  1086.  
  1087.  
  1088. /***************************************************************************
  1089. *   FUNCTION: LFAILCHECK  (STATIC)                                         *
  1090. *                                                                          *
  1091. *   DESCRIPTION:                                                           *
  1092. *                                                                          *
  1093. *       This function checks to see if the status value passed to it is    *
  1094. *       EMMOOPS and exits if it is. failcheck() is used when a function    *
  1095. *       is expected to succeed. Does some clean up before exiting.         *
  1096. *                                                                          *
  1097. *   ENTRY:                                                                 *
  1098. *                                                                          *
  1099. *       function - name of function which may have goofed                  *
  1100. *       status   - status value to be checked                              *
  1101. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1102. *                  freed if NULL.                                          *
  1103. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1104. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1105. *                                                                          *
  1106. *   EXIT:                                                                  *
  1107. *                                                                          *
  1108. *       Void, or may not return.                                           *
  1109. *                                                                          *
  1110. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1111. *                                                                          *
  1112. ***************************************************************************/
  1113. static void lfailcheck(char *function, int status, void far *tofree1,
  1114.                                                       int tofree2, int tofree3)
  1115. {
  1116.     if (status == EMMOOPS)
  1117.     {
  1118.         printf("%s failed, code 0x%X.\n", function, (unsigned int) _EMMerror);
  1119.         if (tofree1 != (void *) NULL)
  1120.         {
  1121.             LFREE(tofree1);
  1122.         }
  1123.         if (tofree2 != 0)
  1124.         {
  1125.             EMMfree(tofree2);
  1126.         }
  1127.         if (tofree3 != 0)
  1128.         {
  1129.             EMMfree(tofree3);
  1130.         }
  1131.         exit(3);
  1132.     }
  1133.  
  1134.     return;
  1135. } /* end of lfailcheck() */
  1136.  
  1137.  
  1138. /***************************************************************************
  1139. *   FUNCTION: LNOFAILCHECK  (STATIC)                                       *
  1140. *                                                                          *
  1141. *   DESCRIPTION:                                                           *
  1142. *                                                                          *
  1143. *       This function checks to see if the status value passed to it is    *
  1144. *       0 and exits if it is. nofailcheck() is used when a function is     *
  1145. *       expected to fail. Does some clean up before exiting.               *
  1146. *                                                                          *
  1147. *   ENTRY:                                                                 *
  1148. *                                                                          *
  1149. *       function - name of function which may have goofed                  *
  1150. *       status   - status value to be checked                              *
  1151. *       tofree1  - conventional memory block to be freed on exit. Not      *
  1152. *                  freed if NULL.                                          *
  1153. *       tofree2  - EMS handle to be freed on exit. Not freed if 0.         *
  1154. *       tofree2  - another EMS handle to be freed on exit. Not freed if 0. *
  1155. *                                                                          *
  1156. *   EXIT:                                                                  *
  1157. *                                                                          *
  1158. *       Void, or may not return.                                           *
  1159. *                                                                          *
  1160. *   CONSTRAINTS/SIDE EFFECTS:                                              *
  1161. *                                                                          *
  1162. ***************************************************************************/
  1163. static void lnofailcheck(char *function, int status, void far *tofree1,
  1164.                                                       int tofree2, int tofree3)
  1165. {
  1166.     if (status == 0)
  1167.     {
  1168.         printf("%s did not fail.\n", function);
  1169.         if (tofree1 != (void *) NULL)
  1170.         {
  1171.             LFREE(tofree1);
  1172.         }
  1173.         if (tofree2 != 0)
  1174.         {
  1175.             EMMfree(tofree2);
  1176.         }
  1177.         if (tofree3 != 0)
  1178.         {
  1179.             EMMfree(tofree3);
  1180.         }
  1181.         exit(3);
  1182.     }
  1183.  
  1184.     return;
  1185. } /* end of lnofailcheck() */
  1186.  
  1187.